package com.sky.edumanageapi.course.controller;

import com.sky.edumanageapi.base.response.JsonResult;
import com.sky.edumanageapi.course.pojo.dto.CourseParam;
import com.sky.edumanageapi.course.pojo.dto.CourseQuery;
import com.sky.edumanageapi.course.pojo.vo.CourseVO;
import com.sky.edumanageapi.course.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "课程模块")
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;

    @ApiOperation("课程列表")//只看课程名字
    @GetMapping("/select")
    public JsonResult selectCourse(CourseQuery courseQuery) {
        log.debug("查询课程列表:{}", courseQuery);
        List<CourseVO> list = courseService.select(courseQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("课程详情")//点击某一课程查询课程详情
    @GetMapping("/detail/{courseId}")
    public JsonResult selectDetail(@PathVariable Integer courseId) {
        log.debug("查询课程详情:{}", courseId);
        CourseVO courseVO = courseService.selectDetail(courseId);
        return JsonResult.ok(courseVO);
    }

    @ApiOperation("搜索课程")//根据课程名与价位搜索课程
    @GetMapping("/search")
    public JsonResult search(CourseParam courseParam){
        log.debug("搜索课程:{}", courseParam);
        List<CourseVO> list = courseService.search(courseParam);
        return JsonResult.ok(list);
    }

    @ApiOperation("我的课程")
    @GetMapping("/myCourse/{userId}")
    public JsonResult searchMyCourse(@PathVariable Integer userId){
        log.debug("我的课程:{}", userId);
        List<CourseVO> list = courseService.myCourse(userId);
        return JsonResult.ok(list);
    }
















}
